package com.jlastu.znb.sc;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import androidx.appcompat.app.AppCompatActivity;

import com.jlastu.znb.R;
import com.jlastu.znb.adapter.scAdapter;
import com.jlastu.znb.adapter.scAdapter;

public class scActivity extends AppCompatActivity {
    private scAdapter scAdapter;
    private ListView scListView;
    private scManager scManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.sc); // 使用收藏布局文件

        scManager = new scManager(this);
       scListView = findViewById(R.id.sc_list_view1);
       scAdapter = new scAdapter(this,scManager.getscItems());
        scListView.setAdapter(scAdapter);

        // 设置收藏列表项点击事件，用于删除操作
        scListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                scItem itemToRemove = scAdapter.getItem(position);
                scManager.removeFromsc(itemToRemove.getId());
                scAdapter.remove(itemToRemove);
                scAdapter.notifyDataSetChanged();
            }
        });
    }
}